package com.example.mobile2030606155byl0615class30work;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import org.jetbrains.annotations.NotNull;

import java.util.List;

public class UserRViewAdapter extends RecyclerView.Adapter<UserRViewAdapter.ViewHolder> {
    private List<Users>list;
    public UserRViewAdapter(List<Users>list){
        this.list = list;
    }
    public class ViewHolder extends RecyclerView.ViewHolder{
        TextView tvitemId,tvitemName,tvitemAge,tvitemScore;
        public ViewHolder(@NonNull @NotNull View itemView) {
            super(itemView);
            tvitemId = itemView.findViewById(R.id.tvitemid);
            tvitemName = itemView.findViewById(R.id.tvitemName);
            tvitemAge = itemView.findViewById(R.id.tvitemAge);
            tvitemScore = itemView.findViewById(R.id.tvitemScore);
        }
    }
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_rv_main_user,parent,false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull UserRViewAdapter.ViewHolder holder, int position) {
        Users users = list.get(position);
        holder.tvitemId.setText(String.valueOf(users.get_id()));
        holder.tvitemName.setText(users.getName());
        holder.tvitemAge.setText(String.valueOf(users.getAge()));
        holder.tvitemScore.setText(String.valueOf(users.getScore()));

    }

    @Override
    public int getItemCount() {
        return list.size();
    }


}
